package com.mikufufu.blog.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MyBatisPlus配置类
 * 
 */
@Configuration
public class MyBatisPlusConfig {

    /**
     * 创建并配置MybatisPlusInterceptor，用于分页拦截。
     *
     * @return MybatisPlusInterceptor 分页拦截器实例
     */
    @Bean
    public MybatisPlusInterceptor paginationInterceptor(){
        // 初始化MybatisPlusInterceptor
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();

        // 创建分页内部拦截器并配置
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        // 设置是否允许页数溢出,默认false意思是不允许
        paginationInnerInterceptor.setOverflow(false);
        // 设置最大限制条数为不限制
        paginationInnerInterceptor.setMaxLimit(-1L);
        // 设置数据库类型
//        paginationInnerInterceptor.setDbType(DbType.getDbType("mysql"));
        paginationInnerInterceptor.setDbType(DbType.MYSQL);

        // 将分页内部拦截器添加到MybatisPlusInterceptor中
        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
        // 添加阻止攻击拦截器
        mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());

        return mybatisPlusInterceptor;
    }


}
